﻿using System;
using System.Collections.Generic;
using GraphProcessor;
using IQIGame.Onigao.Logic;
using UnityEngine;

namespace IQIGame.Onigao.GamePlay.Editors
{
    [System.Serializable, NodeMenuItem(LevelEditorConst.Execution + "/" + LevelEditorConst.AddItem, typeof(LevelServiceGraph))]
    public class LevelServiceExecutionNode_AddItem : LevelServiceExecutionNode
    {
        protected override ServiceExecutionType mServiceType => ServiceExecutionType.AddItem;
        public override string name => LevelEditorConst.AddItem;
        public List<AddItem> items;

        protected override LevelServiceCustomConfig CreateConfig()
        {
            var rList = new List<ItemCidNumPair>();
            if (this.items != null && this.items.Count > 0)
            {
                for (int i = 0; i < this.items.Count; i++)
                {
                    rList.Add(new ItemCidNumPair(this.items[i].itemId, this.items[i].itemCount));
                }
            }
            var rConfig = new LevelServiceExecutionCustom_AddItem()
            {
                items = rList
            };
            return rConfig;
        }

        protected override void OnSync(EditorLevelServiceExecutionConfig newConfig, LevelServiceExecutionNode tempNode)
        {
            if (tempNode is LevelServiceExecutionNode_AddItem rNode)
            {
                this.items = rNode.items;
            }
        }

        [Serializable]
        public class AddItem
        {
            [LevelServiceEditorCustomProperty(ServiceExecutionType.AddItem, "Item表ID")]
            public int itemId;
            [LevelServiceEditorCustomProperty(ServiceExecutionType.AddItem, "道具数量")]
            public int itemCount;
        }
    }
}